import 'package:flutter/material.dart';
import 'package:ty_music_app/api/hello.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: '天一音乐'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  String _message ='天一音乐';

  final ButtonStyle _buttonStyle=ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  void _fetchData(){
    sayHello().then((value) => {
      setState(() { _message=value; })
    });
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(_message,style: Theme.of(context).textTheme.headline5),
            ElevatedButton(
                style:_buttonStyle,
                onPressed: _fetchData,
                child: const Text("请求数据")
            ),
            const SizedBox(height: 20,),
            const Text(
              '你已经点击次数为:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Text('点击'),
      ),
    );
  }
}
